package com.pkutech.carcasher.activity;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.afollestad.materialdialogs.AlertDialogWrapper;
import com.pkutech.carcasher.R;
import com.pkutech.carcasher.db.RealmManager;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
 * Created by cyy on 2016/6/1.
 */
public class HomeActivity extends AppCompatActivity {

    // 写一个广播的内部类，当收到动作时，结束activity
    private BroadcastReceiver mFinishReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            ((Activity) context).finish();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        ButterKnife.bind(this);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
//        getSupportActionBar().setDisplayShowTitleEnabled(false);
        // 在当前的activity中注册关闭广播
        IntentFilter filter = new IntentFilter();
        filter.addAction("finish");
        registerReceiver(mFinishReceiver, filter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.home_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.sys_msg) {
            Intent intent = new Intent(this, SystemMsgActivity.class);
            startActivity(intent);
            return true;
        }

        return super.onOptionsItemSelected(item);
    }


    /**
     * 订单查询
     * @param view
     */
    @OnClick(R.id.queryOrder)
    public void queryOrder(View view) {
        Intent intent = new Intent(this, OrderQueryActivity.class);
        startActivity(intent);
    }

    /**
     * 停靠管理
     * @param view
     */
    @OnClick(R.id.stopManager)
    public void queryHistoryParking(View view) {
        Intent intent = new Intent(this, StopQueryActivity.class);
        startActivity(intent);
    }

    /**
     * 缴费服务
     * @param view
     */
    @OnClick(R.id.paymentManager)
    public void payParking(View view) {
        Intent intent = new Intent(this, PaymentServiceActivity.class);
        startActivity(intent);
    }



    /**
     * 违停提醒
     * @param view
     */
    @OnClick(R.id.hmdManager)
    public void hmdManager(View view) {
        Intent intent = new Intent(this, IllegalParkedWarnActivity.class);
        startActivity(intent);
    }

    /**
     * 消息管理
     * @param view
     */
    @OnClick(R.id.msgManager)
    public void msgManager(View view) {
        Intent intent = new Intent(this, MsgManagedActivity.class);
        startActivity(intent);
    }

    public void getUserInfo(View view){
        Intent intent = new Intent(this, UserDetailActivity.class);
        startActivity(intent);
    }

    public void declareIllegalPark(View view){
        Intent intent = new Intent(this, IllegalParkedDeclareActivity.class);
        startActivity(intent);
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(mFinishReceiver);
    }
}
